/*
 * @Author: windys
 * @Description: 
 * @Date: 2022-02-21 13:59:49
 */
import storage from '@/utils/storage'
import router from '@/router'
import { Dialog } from 'vant'
export default (App) => {
    App.directive('login', {
        mounted(el, binding) {
            el.addEventListener("click", e => {
                const user = storage.getStorage('v3_userinfo_mobile')
                if (!user) {
                    Dialog.confirm({
                        title: '提示',
                        message:
                            '该操作需要登录',
                    })
                        .then(() => {
                            router.push('/login')
                        })
                        .catch(() => {
                        });
                } else {
                    if (typeof binding.value === 'string') {
                        router.push(binding.value)
                    }
                    if (typeof binding.value === 'function') {
                        binding.value()
                    }
                }
            })
        }
    })


    App.directive('drag', {
        mounted(el, binding) {
            el.addEventListener("touchmove", e => {
                e.stopPropagation()
                e.preventDefault()
                el.style.left = e.touches[0].clientX - 30 + 'px'
                el.style.top = e.touches[0].clientY - 30 + 'px'
            })
        }
    })
}


